#pragma once
#include "stdafx.h"
//-------------------------------------------------------------------------------------------------
//ImageExpt.h  - Declaration of Image Experiment           
//-------------------------------------------------------------------------------------------------
//FreeBSD License
//Copyright 2012 Will Stott All rights reserved.
//
//Redistribution and use in source and binary forms, with or without modification, are
//permitted provided that the following conditions are met:
//
//   1. Redistributions of source code must retain the above copyright notice, this list of
//      conditions and the following disclaimer.
//
//   2. Redistributions in binary form must reproduce the above copyright notice, this list
//      of conditions and the following disclaimer in the documentation and/or other materials
//      provided with the distribution.
//
//THIS SOFTWARE IS PROVIDED BY Will Stott ``AS IS'' AND ANY EXPRESS OR IMPLIED
//WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND
//FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL Will Stott OR
//CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
//CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR
//SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON
//ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING
//NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF
//ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
//
//The views and conclusions contained in the software and documentation are those of the
//authors and should not be interpreted as representing official policies, either expressed
//or implied, of Will Stott.
//
//----Authors--------------------------------------------------------------------------------------
//created by: will.stott@ucl.ac.uk Feb 2012
//
//----Comments-------------------------------------------------------------------------------------
//
//-------------------------------------------------------------------------------------------------
#ifdef PLUGINICPROCSTEPS_EXPORTS
#define PLUGINICPROCSTEPS_API __declspec(dllexport)
#else
#define PLUGINICPROCSTEPS_API __declspec(dllimport)
#endif

#include <vector>
#include <string>

#include "TinyXmlLib.h"
#include "TinyXmlHelper.h"

//#include "ImageDataset.h"
#include "ImageProcStepLibAuto.h"


class PLUGINICPROCSTEPS_API ImageExpt
{
public:
	static const char * const ImageExpt::Invalid;
	static const char * const ImageExpt::NotFound;
	static const char * const ImageExpt::IefRefPrefix;
	static const char * const Editor;

	static const char * const xmlHeaderInfo;		//same as ImageDataset::xmlHeaderInfo
	static const char * const xmlHeaderInfoIDFRef;	//same as ImageDataset::xmlHeaderIDFRef
	static const char * const xmlHeaderInfoIEFRef;
	static const char * const xmlHeaderInfoOwner;
	static const char * const xmlHeaderInfoCreateDate;
	static const char * const xmlHeaderInfoEditor;
	static const char * const xmlHeaderInfoIEFDescription;
	static const char * const xmlHeaderInfoIEFVersion;


	static const char * const DateTimeFrmStr;			//match with ImageProcessFile::DateTimeFrmStr and ImageDataset::DateTimeFrmStr

	static const int		  DateTimeFrmStrLen = 20;	//match with ImageProcessFile::DateTimeFrmStr and ImageDataset::DateTimeFrmStr
	static const int		  OwnerLenMax = 25;			//match with ImageProcessFile::OwnerLenMax and ImageDataset::OwnerLenMax
	static const int		  IEFRefLenMax  = sizeof(ImageExpt::IefRefPrefix) + 1 + ImageExpt::OwnerLenMax + 1 + DateTimeFrmStrLen + 1;	//match with ImageProcessFile::IPFRefMax and ImageExpt::IEFRefMax


	enum CreateMode 
	{
		FromDefaults = 0,
		FromTempate,
		FromFile
	};

private:
	TiXmlDocument *_pDoc;
	TiXmlElement  *_pHeader;
	TiXmlElement  *_pHeaderProcSteps;
	TiXmlElement  *_pBody;
	TiXmlElement  *_pBodyImages;
	char		  *_pStrFilePathNameBuffer;

#pragma warning(disable:4251)
	std::string    _IEFPathFileName;
	std::string		_IefRef;
	std::string		_Owner;
	std::string     _CreateDate;
	std::string     _Description;
#pragma warning(default:4251)

public:
					 ~ImageExpt(void);

	static ImageExpt *CreateImageExpt(const wchar_t *PathFileNameIEF, const wchar_t *TemplateIEF, const wchar_t *IefOwner, const wchar_t *Description, ImageExpt::CreateMode mode);

	void		      DeleteMe();
	bool			  SaveFile(); 

	bool   IsValidHeader() { return (_pHeader != '\0')  ? true : false; }
	bool   IsValidBody() { return (_pBody != '\0') ? true : false; }

	TiXmlElement  *GetHeader() {  return _pHeader; }
	TiXmlElement  *GetHeaderProcSteps() { return _pHeaderProcSteps; }
	TiXmlElement  *GetBody() { return _pBody; }
	TiXmlElement  *GetBodyImages() { return _pBodyImages; }
	bool		   InsertImage(TiXmlElement*  image) { return ((image != '\0') && (_pBodyImages != '\0')) ? (_pBodyImages->InsertEndChild(*image) != '\0') : false; }

	const char    *GetOwner() { return _Owner.c_str(); }	
	const char    *GetDescription() { return _Description.c_str(); }	
	const char    *GetIefRef() { return _IefRef.c_str(); }	
	const char    *GetPathFileName() { return _IEFPathFileName.c_str(); }

private:
	ImageExpt(void);

	bool	CreateHeader(TiXmlElement * content, TiXmlElement * templateHdrContent);
	bool	CreateBody(TiXmlElement * content, TiXmlElement * templateBodyContent);

	void	SetIdentity();
	bool    SetHeaderInfo(const char *editor, const char *version);

};

//-------------------------------------------------------------------------------------------------
//			E N D   O F   F I L E
//-------------------------------------------------------------------------------------------------



